package pool

import (
	"fmt"
	"github.com/jmoiron/sqlx"
	"log"
	"os"
	"push/global"
)

//redis初始化链接
func InitMysql() *sqlx.DB{
	mysqlCFG :=global.GLOBAL_MYSQL
	dns := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", mysqlCFG.User, mysqlCFG.Pwd,mysqlCFG.Host, mysqlCFG.Table)
	db, err := sqlx.Connect("mysql", dns)
	if err != nil {
		log.Fatalln(err)
	}
	//defer db.Close()
	return db
}

func MysqlClose(mysql_conn sqlx.DB){
	mysql_conn.Close()
}

//定义一个通用的错误处理函数
func ErrorHandler(err error, where string) {
	if err != nil {
		fmt.Println("出现错误：", err, where)
		os.Exit(1)
	}
}